using System;
using System.Collections.Generic;
using System.Linq;
using axCommerce.Data.Interface;

namespace axCommerce.Data
{
	public partial class AccessRole : IComparable<AccessRole>, IEquatable<AccessRole>, ISimpleData
	{
		public static AccessRole SearchByName(string roleName)
		{
			return Search(new AccessRole
			              	{
			              		Name = roleName,
			              		IsDeleted = false
			              	}).FirstOrDefault();
		}

		public static List<AccessRole> GetAllRoles()
		{
			return Search(new AccessRole
			              	{
			              		IsDeleted = false
			              	});
		}

		public void Save()
		{
			CreatedDate = DateTime.Now;
			LastModifiedDate = DateTime.Now;
			IsDeleted = false;

			Insert();
		}

		public void UpdateInstance()
		{
			LastModifiedDate = DateTime.Now;

			Update();
		}

		public void MarkAsDeleted()
		{
			LastModifiedDate = DateTime.Now;
			IsDeleted = true;

			Update();
		}

		public int CompareTo(AccessRole other)
		{
			return Name.CompareTo(other.Name);
		}

		public bool Equals(AccessRole other)
		{
			return 
				AccessRoleId.Equals(other.AccessRoleId) && Name.Equals(other.Name) && 
				Description.Equals(other.Description) && CreatedDate.Equals(other.CreatedDate) && 
				IsDeleted.Equals(other.IsDeleted) && LastModifiedDate.Equals(other.LastModifiedDate);
		}
	}
}

